package com.bzg.manager.controller;



import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bzg.manager.bean.LinkInfo;
import com.bzg.manager.bean.PartInfo;
import com.bzg.manager.exception.BaseExceptionTool;
import com.bzg.manager.param.BusiQueryParam;
import com.bzg.manager.param.UserParam;
import com.bzg.manager.service.PersonCenterService;
import com.bzg.manager.service.UserService;
import com.bzg.manager.utils.PageBean;
import com.bzg.manager.utils.RespBody;
import com.wordnik.swagger.annotations.ApiOperation;

@Controller
@RequestMapping("/api/perCenter")
public class PersonCenterController extends BaseController {
	
	public static final Logger log = LoggerFactory.getLogger(PersonCenterController.class);
	
	@Autowired
	private PersonCenterService personCenterService;
	@Autowired
	private UserService userService;
	
	
	@RequestMapping(value="/getPartInfo",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="零部件信息查询")
	public RespBody getPartInfo(@RequestBody JSONObject json){
		BusiQueryParam param = JSON.toJavaObject(json.getJSONObject("info"), BusiQueryParam.class);
		if(param == null || StringUtils.isEmpty(param.getVendCode())){//查询条件为空时抛出异常
			throw BaseExceptionTool.PARAM_IS_NULL;
		}
		//目前不实现分页功能，将分页信息设为null
		param.setCurrPage(null);
		param.setPageSize(null);
		
		PageBean<PartInfo> partInfo = personCenterService.getPartInfo(param);
		return RespBody.ok(partInfo);
	}
	
	@RequestMapping(value="/feedback",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="意见反馈")
	public RespBody feedback(@RequestBody JSONObject json){
		UserParam userParam = JSON.toJavaObject(json.getJSONObject("info"), UserParam.class);
		String feedback = userService.feedback(userParam);
		if("Y".equals(feedback)){
			return RespBody.ok("");
		}
		return  RespBody.error("1008", "意见反馈失败！");
	}
	
	
	@RequestMapping(value="/compLink",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="本司联系人")
	public RespBody compLink(@RequestBody JSONObject json){
		UserParam param = JSON.toJavaObject(json.getJSONObject("info"), UserParam.class);
		List<LinkInfo> list = personCenterService.getComLink(param);
		return RespBody.ok(list);
	}
	
	@RequestMapping(value="/bzgLink",method=RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value="BZG联系人")
	public RespBody bzgLink(@RequestBody JSONObject json){
		UserParam userParam = new UserParam();
		userParam.setVendCode("CZZG");
		List<LinkInfo> list = personCenterService.getComLink(userParam);
		return RespBody.ok(list);
	}
	
}
